package cn.baddonkey.superqueryjavasdk.json;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;

import java.lang.reflect.Type;

public class FastjsonParser implements JsonParser {
    @Override
    public <T> T from(String json, Class<T> type) {
        return JSON.parseObject(json, type);
    }

    @Override
    public String to(Object o) {
        return JSON.toJSONString(o);
    }

    @Override
    public <T> T from(String json, Type type) {
        return JSON.parseObject(json, this.getType(type));
    }

    @Override
    public Type getType(Type type) {
        return TypeReference.get(type).getType();
    }
}
